#ifndef _MY_MQTT_H
#define _MY_MQTT_H

#include <PubSubClient.h>
#include <WiFiClient.h>

#define MQTT_CYCLE 100

enum class MQTT_STATUS : char
{
    INIT = 0,
    CONNECT,
    SUBSCRIBE,
    RUNNING
};

class MyMqtt
{
private:
    const char* _server;
    uint16_t    _port;
    const char* _token;
    const char* _topic0;
    const char* _topic2;
    std::function<void(char*, uint8_t*, unsigned int)> _callback;

    WiFiClient*   _client;
    PubSubClient* _mqtt;
    MQTT_STATUS   _state;

private:
    bool init();
    bool connect();
    bool getStatus();
    bool subscribe();
    bool publish(const char* msg);

public:
    MyMqtt(void);
    ~MyMqtt(void);

public:
    void stateMachine(void);
    void configArg(const char* server, uint16_t port, const char* token, const char* topic0, const char* topic2, MQTT_CALLBACK_SIGNATURE);
};

#endif //_MY_MQTT_H
